package org.example.service.impl;

import org.example.data.WorkEvent;
import org.example.listener.WorkApplicationEvent;
import org.example.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public String testEvent(Integer id) {
        WorkEvent workEvent = new WorkEvent();
        workEvent.setState(id);
        workEvent.setContents("监听事件为：WorkEvent");
        WorkApplicationEvent event = new WorkApplicationEvent(workEvent);
        System.out.println("推送监听事件");
        // 发布事件
        applicationEventPublisher.publishEvent(event); 
        System.out.println("已推送成功");
        return "推送成功";
    }
}
